﻿@model IEnumerable<ZdSoft.Model.User>

@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<p>
    @Html.ActionLink("创建新用户", "Create")
    <input type="text" required lay-verify="required" placeholder="请输入搜索内容" autocomplete="off" class="layui-input-block" style="width:480px" />
    <input type="button" value="搜索" class="layui-btn" />
</p>
<table class="layui-table">
    <thead>
        <tr>
            <th hidden="hidden">ID</th>
            <th>
                @Html.DisplayNameFor(model => model.UserName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Account)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.IsActive)
            </th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        @{
            if ( Model==null||Model.Count() <= 0)
            {
                <tr>
                    <td colspan="4" style="text-align:center">
                        没有数据
                    </td>
                </tr>
            }
            else
            {
                foreach (var item in Model)
                {
                    <tr id=@item.ID>
                        <td>
                            @Html.DisplayFor(modelItem => item.UserName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Account)
                        </td>
                        <td>
                            @{
                    if (item.IsActive)
                    {
                        @:激活状态
                        }
                    else
                    {
                        @:未激活状态
                        }
                            }
                        </td>
                        <td>
                            @Html.ActionLink("Edit", "Edit", new { userID = item.ID }) |
                            @Html.ActionLink("Details", "Details", new { userID = item.ID }) |
                            @Html.ActionLink("Delete", "Delete", new { userID = item.ID })
                        </td>
                    </tr>
                }
            }
        }
    </tbody>
</table>
<div id="page"></div>
<script>
    $(function () {
        layui.use('laypage', function () {
            var laypage = layui.laypage;

            //执行一个laypage实例
            laypage.render({
                elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
              , count: @ViewBag.userCount //数据总数，从服务端得到
              , layout: ['count', 'prev', 'page', 'next', 'skip']
              , jump: function (obj,first) {
                  if(!first)
                      {
                  $.post("../User/Index",{pageSize:obj.limit,pageIndex:obj.curr},function(data){
                      //console.log(data);
                      $("tbody").html("");
                      $.each($.parseJSON(data),function(index,obj){
                          //console.log(obj);
                          var tempIsActive= obj.IsActive==true?"激活状态":"未激活状态";
                          var tbodyhtm="<tr>"+
                          "<td>"+
                              obj.UserName+
                          "</td>"+
                          "<td>"+
                              obj.Account+
                          "</td>"+
                          "<td>"+
                              tempIsActive+
                          "</td>"+
                          "<td>"+
                              "<a href='/User/Edit?uid="+obj.ID+"'>Edit</a>"+"|"+
                              "<a href='/User/Details?uid="+obj.ID+"'>Details</a>"+"|"+
                              "<a href='/User/Delete?uid="+obj.ID+"'>Delete</a>"+
                          "</td>"+
                      "</tr>";
                          console.log(tbodyhtm);
                          $("tbody").append(tbodyhtm);
                      });
                  });
                  }
              }
            });
        });
        //a标签的信息，要是是删除或者修改则需要提示
        $("a").click(function () {
            switch ($(this).text().trim()) {
                case "Edit":
                    return confirm("你确认修改吗？"); break;
                case "Delete":
                    return confirm("你确认删除吗？"); break;
                default:
                    break;
            }
        });
    });
</script>
